package com.kikt.commonutils;

import android.app.Application;
import android.widget.Toast;

/**
 * Created by kikt on 2016/1/9.
 */
public class ToastUtils {

    private static Toast toast;
    private static Application application;

    /**
     * 初始化utils，决定弹出toast的application
     *
     * @param application application
     */
    public static void init(Application application) {
        ToastUtils.application = application;
    }


    public static void toast(CharSequence text) {
        toast(text, 0);
    }

    public static void toast(CharSequence text, int duration) {
        if (toast == null) {
            toast = Toast.makeText(application, text, duration);
        } else {
            toast.setText(text);
        }
        toast.show();
    }

    public static void toast(int text) {
        toast(text, 0);
    }

    public static void toast(int text, int duration) {
        if (toast == null) {
            toast = Toast.makeText(application, text, duration);
        } else {
            toast.setText(text);
        }
        toast.show();
    }
}
